<template>
  <div id="login">
    <div style="display: grid;justify-content: center">
      <div style="display: flex;align-items: end;margin-top: 50px">
        <div class="logo"></div>
        <div class="right"></div>
      </div>
      <div class="bottom"></div>
    </div>
    <div style="text-align: center;margin-top: 250px;display: grid;justify-content: center;font-size: larger">
      <div style="width: 180px;height: 50px;line-height: 50px;color: white;" class="loginBtn" @click="openLogin">登录</div>
      <div style="width: 180px;height: 50px;line-height: 50px;color: white;" class="registerBtn" @click="openRegister">免费注册</div>
    </div>



<!--    用户登录-->
    <el-dialog
        title="用户登录"
        :visible.sync="dialogVisible"
        width="30%"
    >
      <el-form ref="form" :model="loginForm" label-width="80px">
        <el-form-item label="账号">
          <el-input v-model="loginForm.account"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="loginForm.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button  type="primary" @click="executeLogin">立即登录</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

<!--    免费注册-->
    <el-dialog
        title="免费注册"
        :visible.sync="dialogVisible2"
        width="30%"
    >
      <el-form ref="form" :model="registerForm" label-width="100px">
        <el-form-item label="昵称">
          <el-input v-model="registerForm.username"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="registerForm.phone"></el-input>
        </el-form-item>
        <el-form-item label="账号">
          <el-input v-model="registerForm.account"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="registerForm.password"></el-input>
        </el-form-item>
        <el-form-item label="再次确认密码">
          <el-input type="password" v-model="registerForm.confirmPassword"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button  type="primary" @click="executeRegister">立即注册</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {register} from "@/api/register";

export default {
  data(){
    return {
      dialogVisible: false,
      dialogVisible2: false,
      loginForm:{
        account:undefined,
        password:undefined
      },
      registerForm:{
        account:undefined,
        password:undefined,
        confirmPassword:undefined,
        username:undefined,
        phone:undefined,
      }
    }
  },
  methods:{
    // 打开登录窗口
    openLogin(){
      this.dialogVisible = true
    },
    // 执行登录操作
    executeLogin(){
      this.$store.dispatch("Login",this.loginForm).then(() => {
        this.$router.push("/")
      }).catch(() => {
      })
    },

    // 打开注册窗口
    openRegister(){
      this.dialogVisible2 = true
    },

    // 执行注册操作
    executeRegister(){
      register(this.registerForm).then(() => {
        this.$message('注册成功');
        this.dialogVisible2 = false
      }).catch(() => {

      })
    }


  }
}
</script>


<style scoped>
#login{
  background-image: url("../assets/images/login-bg.jpg");
  background-size: cover;
  background-position: center;
  min-height: 98vh;
  margin: 0;
  padding: 0;
}
.logo{
  background-image: url("../assets/images/logo.png");
  background-position: center;
  background-size: cover;
  height: 124px;
  width: 350px;
}
.right{
  background-image: url("../assets/images/2.png");
  background-position: center;
  background-size: cover;
  height: 34px;
  width: 146px;
}
.bottom {
  margin-top: 20px;
  background-image: url("../assets/images/1.png");
  background-position: center;
  background-size: cover;
  height: 29px;
  width: 475px;
  margin-left: 50px;
}
.loginBtn:hover{
  background-color: aqua;
  color: white;
  cursor: pointer;
}
.registerBtn:hover{
  background-color: aqua;
  color: white;
  cursor: pointer;
}

</style>